package com.xavier.dong.nio.zerocopy;

import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author XavierDong
 **/
public class OldIOClient {

    public static void main(String[] args) {


        String filename = "/Users/xavierdong/Documents/office/Parallels_Desktop14.0.1.dmg";


        try (FileInputStream fileInputStream = new FileInputStream(filename);

             Socket socket = new Socket("localhost", 7001);
             DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());

        ) {
            byte[] bytes = new byte[4096];
            long readCount;
            long total = 0;

            long startTime = System.currentTimeMillis();

            while ((readCount = fileInputStream.read(bytes)) > 0) {
                total += readCount;
                dataOutputStream.write(bytes);
            }

            System.out.println("发送总字节数: " + total + ", 耗时: " + (System.currentTimeMillis() - startTime));

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
